package game.behaviours;

import edu.monash.fit2099.demo.forest.AttackAction;
import edu.monash.fit2099.engine.actions.Action;
import edu.monash.fit2099.engine.actors.Actor;
import edu.monash.fit2099.engine.actors.Behaviour;
import edu.monash.fit2099.engine.positions.Exit;
import edu.monash.fit2099.engine.positions.GameMap;
import edu.monash.fit2099.engine.positions.Location;
import game.actors.Player;

/**
 * 如果相邻格有 Player，则返回攻击该 Player 的 Action；否则返回 null。
 */
public class AttackBehaviour implements Behaviour {

    @Override
    public Action generateAction(Actor actor, GameMap map) {
        Location here = map.locationOf(actor);
        for (Exit exit : here.getExits()) {
            Location dest = exit.getDestination();
            if (dest.containsAnActor() && dest.getActor() instanceof Player) {
                // 使用我们在 game 包内的 AttackAction
                return new AttackAction(dest.getActor(), exit.getName());
            }
        }
        return null;
    }
}
